package group.program.Config;

import group.program.properties.DataSourceProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

@Configuration
@Slf4j
public class DatabaseConfig {
    private Map<String, DataSource> dataSourceMap = new HashMap<>();

    public void addDataSource(DataSourceProperties properties) {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName(properties.getDriverClassName());
        dataSource.setUrl(properties.getUrl());
        dataSource.setUsername(properties.getUsername());
        dataSource.setPassword(properties.getPassword());
        dataSourceMap.put(properties.getName(), dataSource);
    }

    public void removeDataSource(String name) {
        dataSourceMap.remove(name);
    }

    public DataSource getDataSource(String name) {
        return dataSourceMap.get(name);
    }

//    private List<String> Names = new ArrayList<>();
//    private List<String> Urls = new ArrayList<>();
//    private List<String> Usernames = new ArrayList<>();
//    private List<String> Passwords = new ArrayList<>();
//    public void addName(String name) {
//        Names.add(name);
//    }
//
//    public void addUrl(String url) {
//        Urls.add(url);
//    }
//
//    public void addUsername(String username) {
//        Usernames.add(username);
//    }
//
//    public void addPassword(String password) {
//        Passwords.add(password);
//    }
//    public void removeName(String name) {
//        Names.remove(name);
//    }
//
//    public void removeUrl(String url) {
//        Urls.remove(url);
//    }
//
//    public void removeUsername(String username) {
//        Usernames.remove(username);
//    }
//
//    public void removePassword(String password) {
//        Passwords.remove(password);
//    }
}
